/*
 * Copyright (c) 2020 Carnegie Lee
 * All rights reserved
 */
package com.geekc.kafka.consumer;

import com.geekc.kafka.constant.KafkaConst;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.TopicPartition;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

/**
 * 消费者 - Replying模式
 * @author Carnegie Lee
 */
@Component
public class ReplyingConsumer {

    @KafkaListener(id = KafkaConst.KAFKA_CONSUMER_GROUP_REPLYING, topicPartitions = {
            @TopicPartition(topic = KafkaConst.KAFKA_TARGET_TOPIC_REPLYING, partitions = {"0"})
    }, concurrency = KafkaConst.KAFKA_CONSUMER_CONCURRENCY, errorHandler = KafkaConst.KAFKA_CONSUMER_ERROR_HANDLER)
    @SendTo
    public String receiveMessage(String message, Acknowledgment ack) {
        System.out.println("消费者接收到消息" + message.toString());
        System.out.println("消费者准备进行确认...");
        //TODO
        //消息手动签收
        ack.acknowledge();

        return "SUCCESS";
    }
}
